package com.android.job.service.request;

import java.util.ArrayList;

import org.apache.http.NameValuePair;

import android.os.Handler;

import com.android.job.service.JSONRequest;
import com.android.job.util.LogX;
import com.android.job.util.json.JSONException;
import com.android.job.util.json.JSONObject;

public class GetFileInfoRequest extends JSONRequest
{
	private String fileInfo = "";

	public String getFileInfo()
	{
		return fileInfo;
	}

	public void setFileInfo(String fileInfo)
	{
		this.fileInfo = fileInfo;
	}

	DownloadFileRequest downReq;

	/**
	 * @param handler
	 * @param httpUrl    
	 */
	public GetFileInfoRequest(Handler handler, String httpUrl)
	{
		super(handler, httpUrl);
	}

	public GetFileInfoRequest(DownloadFileRequest request, String httpUrl)
	{
		super(httpUrl);
		downReq = request;
	}

	/**
	 * @param json
	 * @return
	 */
	@Override
	protected boolean parseJSONResponse(JSONObject json)
	{
//		if (json.has("successList"))
//		{
//			JSONArray newAppArray = json.getJSONArray("successList");
//			LogX.trace("newAppArray", newAppArray.length() + "");
//			int length = newAppArray.length();
//			JSONObject fileInfo = null;
//			if (length > 0)
//			{
//				fileInfo = newAppArray.getJSONObject(0);
//				if (fileInfo != null)
//				{
//					String downUrl = fileInfo.getString("url").replaceAll(" ",
//							"%20").replace("|", "%7C");
//					if (downReq != null)
//					{
//						downReq.startDownload(downUrl);
//					}
//				}
//			}
//		}
//		if (json.has(FusionField.FAILLIST)
//				&& json.getJSONArray(FusionField.FAILLIST).length() != 0)
//		{
//			//通知上层文件不存在
//			if (downReq != null)
//			{
//				downReq.onError(FusionCode.SRC_FILE_NOT_EXIT, "");
//			}
//		}
		return true;
	}

	/**
	 * 网络不可用处理
	 * @param code    状态码
	 * @param message 异常信息  
	 */
	public void onConnError(int code, String message)
	{
		// 显示错误
		LogX.trace("GetFileInfoRequest", "onConnError " + httpRequestUrl
				+ message);
		if (downReq != null)
		{
			downReq.onConnError(code, message);
		}
	}

	/**
	 * 请求的json中所带的参数    
	 */
	@Override
	protected void appendMainBody()
	{
		this.paramsters = new ArrayList<NameValuePair>();
//		paramsters
//				.add(new BasicNameValuePair(
//						"fields",
//						"[\"size\", \"createTime\", \"modifyTime\", \"url\",\"fileCount\", \"dirCount\", \"md5\"]"));
//		paramsters.add(new BasicNameValuePair("files", fileInfo));
//		paramsters.add(new BasicNameValuePair("nsp_sid", FusionField.HOTALK_SID));
//		paramsters.add(new BasicNameValuePair("nsp_svc", "nsp.vfs.getattr"));
//		paramsters.add(new BasicNameValuePair("nsp_ts", String.valueOf(System
//				.currentTimeMillis() / 1000L)));
//		paramsters.add(new BasicNameValuePair("nsp_key", getKeyData(
//				FusionField.nspSecret, paramsters)));

	}
}
